/*
 * author      : dormi330
 * date        : 2018/6/30
 * description : 统一封装 http 响应
 */

package com.deep.trade.adaptor.provided.rest;

import com.deep.trade.application.AppRuntimeEvn;
import com.deep.trade.common.HttpResponsePayload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HttpResponseAssembler {

    @Autowired
    private AppRuntimeEvn appRuntimeEvn;

    public <T> HttpResponsePayload<T> happy(T payload) {
        return new HttpResponsePayload<T>(appRuntimeEvn.getRequestId(), payload);
    }

    public HttpResponsePayload happy() {
        return new HttpResponsePayload<>(appRuntimeEvn.getRequestId(), null);
    }

    public HttpResponsePayload unhappy(String code, String msg) {
        return new HttpResponsePayload(appRuntimeEvn.getRequestId(), code, msg);
    }

    public HttpResponsePayload unhappy(int code, String msg) {
        return new HttpResponsePayload(appRuntimeEvn.getRequestId(), code + "", msg);
    }
}
